<?php

namespace System\Core;

/**
 * @property enum $Tipo
 * @property System\Core\Config $Config
 * @property System\Core\ConfigItems $Configs
 * @property string $Nome
 * @property string $Valor
 */
final class ConfigItem extends \System\Types\Object
{

    private $_type;
    private $_key;
    private $_value;

    /**
     * @var System\Core\ConfigItems
     */
    private $_configs;

    /**
     * @param int $type
     * @param string $item
     * @param mixed $value
     * @param System\Core\ConfigItems $configs
     */
    public function __construct($type, $item, ConfigItems &$configs)
    {
        $type = (int) $type;

        $this->_configs = $configs;
        $this->_type = $type;

        $this->_key = $item;
        $this->_value = \System\Core\Config::GetValue($type, $item);
    }

    public function __set($name, $value)
    {
        switch ($name)
        {
            case 'Nome':
                Config::Remove($this->_type, $value);
                Config::Set($this->_type, $value, $this->_value);
                $this->_key = $value;
                break;
            case 'Valor':
                Config::Set($this->_type, $this->_key, $value);
                $this->_value = $value;
                break;
            default:
                return null;
                break;
        }
    }

    public function __get($name)
    {
        switch ($name)
        {
            case 'Tipo':
                return $this->_type;
                break;
            case 'Configs':
                return $this->_configs;
                break;
            case 'Config':
                return $this->_configs->Config;
                break;
            case 'Nome':
                return $this->_key;
                break;
            case 'Valor':
                return $this->_value;
                break;
            default:
                return null;
                break;
        }
    }

}